<template>
	<view>
		 <input class="uni-input" focus maxlength="50" v-model="userInfo.email"/>
	</view>
</template>

<script>
	import userService from '../../../api/user.js'
	export default {
		data() {
			return {
				userInfo: {
					id:'',
					email:'',
				}
			};
		},
		onLoad(param) {
			const that = this;
			that.userInfo.id = param.id
			that.userInfo.email = param.email
		},
		//监听导航栏完成按钮
		onNavigationBarButtonTap: function(e) {
			this.onSubmit()
		},
		methods: {
			onSubmit: function() {
				const that = this;
				if(!that.$util.isEmail(that.userInfo.email)) {
					uni.showToast({
						title: '邮箱格式不正确',
						icon:'none'
					});
					setTimeout(function(){
						uni.hideToast();
					},1000)
					return
				}
				userService.updateUserInfo(that.userInfo).then(res=>{
					if(res.success){
						uni.showToast({
							title: '设置邮箱成功'
						});
						setTimeout(function(){
							uni.hideToast();
							uni.navigateBack({
								delta:1,
							})
						},1000)
						
					}
				})
			}
		}
	};
</script>

<style></style>
